/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.qihoo.gamecenter.sdk.login.plugin.accountBind.view;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;
import com.qihoo.gamecenter.sdk.common.i.q;
import com.qihoo.gamecenter.sdk.common.view.CustButton;
import com.qihoo.gamecenter.sdk.common.view.CustEditText;
import com.qihoo.gamecenter.sdk.login.plugin.d.a;
import com.qihoo.gamecenter.sdk.login.plugin.g.j;
import com.qihoo.gamecenter.sdk.login.plugin.g.l;
import com.qihoo.gamecenter.sdk.login.plugin.g.m;
import com.qihoo.gamecenter.sdk.login.plugin.h.e;
import com.qihoo.gamecenter.sdk.login.plugin.h.f;
import java.util.Locale;
import org.json.JSONObject;

public class UnbindPhoneView extends LinearLayout {
    private Intent a;
    private Activity b;
    private com.qihoo.gamecenter.sdk.login.plugin.f.a c;
    private boolean d;
    private TextView e;
    private TextView f;
    private CustEditText g;
    private CustButton h;
    private CustButton i;
    private boolean j;
    private a k;
    private View.OnClickListener l;
    private View.OnClickListener m;

    private UnbindPhoneView(Context paramContext) {
        super(paramContext);
        this.j = false;
        this.l = new View.OnClickListener() {
            public void onClick(View paramView) {
                UnbindPhoneView.e(UnbindPhoneView.this).d();
            }
        };
        this.m = new View.OnClickListener() {
            public void onClick(View paramView) {
                UnbindPhoneView.a(UnbindPhoneView.this);
            }
        };
    }

    public UnbindPhoneView(Activity paramActivity, Intent paramIntent) {
        this(paramActivity);
        this.a = paramIntent;
        this.b = paramActivity;
        this.c = com.qihoo.gamecenter.sdk.login.plugin.f.a.a(getContext());
        this.d = paramIntent.getBooleanExtra("screen_orientation", true);
        a();
    }

    private void a() {
        setOrientation(1);
        setLayoutParams(new LinearLayout.LayoutParams(-1, -2));
        this.e = new TextView(this.b);
        this.e.setLayoutParams(new LinearLayout.LayoutParams(-1, -2));
        this.e.setTextSize(1, f.b(this.b, com.qihoo.gamecenter.sdk.login.plugin.h.c.l));
        this.e.setTextColor(-11776948);
        addView(this.e);
        int i1 = 0;
        int i2 = f.a(this.b, 20.0F);
        if (this.d)
            i1 = f.a(this.b, 15.0F);
        else
            i1 = i2;
        LinearLayout.LayoutParams localLayoutParams1 = new LinearLayout.LayoutParams(-1, f.a(this.b, 47.0F));
        localLayoutParams1.topMargin = i1;
        int i3 = f.a(this.b, 8.0F);
        LinearLayout localLinearLayout1 = new LinearLayout(this.b);
        localLinearLayout1.setLayoutParams(localLayoutParams1);
        localLinearLayout1.setGravity(16);
        localLinearLayout1.setOrientation(0);
        this.c.a(localLinearLayout1, -1073741801);
        localLinearLayout1.setPadding(i3, 0, 0, 0);
        addView(localLinearLayout1);
        this.f = new TextView(this.b);
        this.f.setText(com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.dp));
        this.f.setTextColor(-11776948);
        this.f.setTextSize(1, f.b(this.b, com.qihoo.gamecenter.sdk.login.plugin.h.c.h));
        localLinearLayout1.addView(this.f);
        this.g = new CustEditText(this.b);
        this.g.setLayoutParams(new LinearLayout.LayoutParams(-1, -1));
        this.g.setHint(com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.dq));
        this.g.setBackgroundColor(0);
        this.g.setGravity(16);
        this.g.setSingleLine();
        this.g.setHintTextColor(-3355444);
        this.g.setTextColor(-11776948);
        this.g.setTextSize(1, f.b(this.b, com.qihoo.gamecenter.sdk.login.plugin.h.c.h));
        this.g.setPadding(i3, 0, i3, 0);
        this.g.setImeOptions(6);
        this.g.e();
        this.g.f();
        this.g.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            public boolean onEditorAction(TextView paramTextView, int paramInt, KeyEvent paramKeyEvent) {
                if ((paramInt == 6) || (paramInt == 0)) {
                    UnbindPhoneView.a(UnbindPhoneView.this);
                    return true;
                }
                return false;
            }
        });
        localLinearLayout1.addView(this.g);
        Drawable localDrawable1 = this.c.a(-1073741764);
        Drawable localDrawable2 = this.c.a(-1073741763);
        this.h = new CustButton(this.b);
        this.h.setGravity(17);
        this.h.setTextColor(-1);
        this.h.setText(com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.dr));
        this.h.a();
        this.h.b();
        this.h.setOnClickListener(this.m);
        this.c.a(this.h, localDrawable1, localDrawable2, localDrawable1);
        localDrawable1 = this.c.a(-1073741800);
        localDrawable2 = this.c.a(-1073741799);
        this.i = new CustButton(this.b);
        this.i.setGravity(17);
        this.i.setTextColor(-16777216);
        this.i.setText(com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.b));
        this.i.setVisibility(8);
        this.c.a(this.i, localDrawable1, localDrawable2, localDrawable1);
        this.i.a();
        this.i.b();
        this.i.setOnClickListener(this.l);
        LinearLayout.LayoutParams localLayoutParams2 = new LinearLayout.LayoutParams(-1, -2);
        localLayoutParams2.topMargin = i1;
        LinearLayout localLinearLayout2 = new LinearLayout(this.b);
        localLinearLayout2.setGravity(17);
        LinearLayout.LayoutParams localLayoutParams3;
        if (this.d) {
            localLinearLayout2.setOrientation(0);
            localLayoutParams3 = new LinearLayout.LayoutParams(0, f.a(this.b, 47.0F), 1.0F);
            localLayoutParams3.rightMargin = f.a(this.b, 15.0F);
            localLinearLayout2.addView(this.i, localLayoutParams3);
            localLinearLayout2.addView(this.h, new LinearLayout.LayoutParams(0, f.a(this.b, 47.0F), 1.0F));
        }
        else {
            localLinearLayout2.setOrientation(1);
            localLinearLayout2.addView(this.h, new LinearLayout.LayoutParams(-1, f.a(this.b, 47.0F)));
            localLayoutParams3 = new LinearLayout.LayoutParams(-1, f.a(this.b, 47.0F));
            localLayoutParams3.topMargin = i1;
            localLinearLayout2.addView(this.i, localLayoutParams3);
        }
        addView(localLinearLayout2, localLayoutParams2);
    }

    public void setCancelEnable(boolean paramBoolean) {
        this.i.setVisibility((paramBoolean) ? 0 : 8);
    }

    private void b() {
        this.j = true;
        this.h.setEnabled(true);
        this.i.setEnabled(true);
        this.e.setText(com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.dt));
        this.f.setText(com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.j));
        this.g.setHint(com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.N));
        this.g.setInputType(1);
        this.g.setText("");
    }

    private void c() {
        String str = this.g.getText().toString().trim();
        if (!(a(this.b, str)))
            return;
        this.h.setEnabled(false);
        this.i.setEnabled(false);
        j localj = new j(this.b, this.a);
        localj.b(str);
        localj.a(new com.qihoo.gamecenter.sdk.login.plugin.g.c(localj) {
            public void a(int paramInt, String paramString, JSONObject paramJSONObject) {
                if ((paramInt != 0) || (paramJSONObject == null)) {
                    UnbindPhoneView.b(UnbindPhoneView.this).setEnabled(true);
                    UnbindPhoneView.c(UnbindPhoneView.this).setEnabled(true);
                    return;
                }
                int i = paramJSONObject.optInt("errno", -1);
                switch (i) {
                case 0:
                case 519:
                    com.qihoo.gamecenter.sdk.common.a.c.d(this.a.b());
                    com.qihoo.gamecenter.sdk.login.plugin.h.d.a(this.a.a().a());
                    UnbindPhoneView.d(UnbindPhoneView.this);
                    break;
                case 200:
                    q.a(UnbindPhoneView.this.getContext(), com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.U));
                    break;
                case 219:
                    q.a(UnbindPhoneView.this.getContext(), com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.du));
                    break;
                case 5006:
                    q.a(UnbindPhoneView.this.getContext(), com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.f));
                    break;
                case 5016:
                    q.a(UnbindPhoneView.this.getContext(), com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.d));
                    break;
                case 5018:
                    q.a(UnbindPhoneView.this.getContext(), com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.dv));
                    break;
                case 5020:
                    q.a(UnbindPhoneView.this.getContext(),
                            String.format(com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.T),
                                    new Object[] { Integer.valueOf(2) }));
                    break;
                case 5021:
                    q.a(UnbindPhoneView.this.getContext(),
                            String.format(com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.T),
                                    new Object[] { Integer.valueOf(14) }));
                    break;
                case 5022:
                    q.a(UnbindPhoneView.this.getContext(), com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.W));
                    break;
                case 5023:
                    q.a(UnbindPhoneView.this.getContext(), com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.V));
                    break;
                default:
                    q.a(UnbindPhoneView.this.getContext(), com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.dw));
                }
                if ((i == 0) || (i == 519))
                    return;
                UnbindPhoneView.b(UnbindPhoneView.this).setEnabled(true);
                UnbindPhoneView.c(UnbindPhoneView.this).setEnabled(true);
            }
        }, new String[0]);
    }

    private void d() {
        if (this.g == null)
            return;
        String str = this.g.getText().toString().trim();
        if (TextUtils.isEmpty(str)) {
            this.g.requestFocus();
            q.a(this.b, com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.dx));
            return;
        }
        if (this.k != null)
            this.k.a();
        this.h.setEnabled(false);
        this.i.setEnabled(false);
        new m(this.b, com.qihoo.gamecenter.sdk.common.a.c.d(), com.qihoo.gamecenter.sdk.common.i.k.a(str), null).a(
                new com.qihoo.gamecenter.sdk.login.plugin.g.c() {
                    public void a(int paramInt, String paramString, JSONObject paramJSONObject) {
                        if ((paramInt == 0) && (paramJSONObject != null)) {
                            int i = paramJSONObject.optInt("errno", -1);
                            if (i == 0) {
                                JSONObject localJSONObject = paramJSONObject.optJSONObject("user");
                                if (localJSONObject != null) {
                                    String str1 = localJSONObject.optString("username");
                                    String str2 = localJSONObject.optString("loginemail");
                                    if ((((TextUtils.isEmpty(str1)) || (str1.toUpperCase().startsWith("360U"))))
                                            && (TextUtils.isEmpty(str2))) {
                                        if (UnbindPhoneView.e(UnbindPhoneView.this) != null)
                                            UnbindPhoneView.e(UnbindPhoneView.this).c();
                                        UnbindPhoneView.f(UnbindPhoneView.this);
                                        return;
                                    }
                                }
                                UnbindPhoneView.d(UnbindPhoneView.this);
                            }
                            else if (i == 5025) {
                                if (UnbindPhoneView.e(UnbindPhoneView.this) != null)
                                    UnbindPhoneView.e(UnbindPhoneView.this).c();
                                UnbindPhoneView.b(UnbindPhoneView.this).setEnabled(false);
                                UnbindPhoneView.c(UnbindPhoneView.this).setEnabled(true);
                                q.a(UnbindPhoneView.g(UnbindPhoneView.this),
                                        com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.dy));
                            }
                            else {
                                if (UnbindPhoneView.e(UnbindPhoneView.this) != null)
                                    UnbindPhoneView.e(UnbindPhoneView.this).c();
                                UnbindPhoneView.b(UnbindPhoneView.this).setEnabled(true);
                                UnbindPhoneView.c(UnbindPhoneView.this).setEnabled(true);
                                q.a(UnbindPhoneView.g(UnbindPhoneView.this),
                                        com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.dz));
                            }
                        }
                        else {
                            if (UnbindPhoneView.e(UnbindPhoneView.this) != null)
                                UnbindPhoneView.e(UnbindPhoneView.this).c();
                            UnbindPhoneView.b(UnbindPhoneView.this).setEnabled(true);
                            UnbindPhoneView.c(UnbindPhoneView.this).setEnabled(true);
                            q.a(UnbindPhoneView.g(UnbindPhoneView.this),
                                    com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.dz));
                        }
                    }
                }, new String[0]);
    }

    private void e() {
        f.a(this.b);
        if (this.j)
            c();
        else
            d();
    }

    private void f() {
        new l(this.b).a(new com.qihoo.gamecenter.sdk.login.plugin.g.c() {
            public void a(int paramInt, String paramString, JSONObject paramJSONObject) {
                if (UnbindPhoneView.e(UnbindPhoneView.this) != null)
                    UnbindPhoneView.e(UnbindPhoneView.this).c();
                if ((paramInt != 0) || (paramJSONObject == null)) {
                    UnbindPhoneView.b(UnbindPhoneView.this).setEnabled(true);
                    UnbindPhoneView.c(UnbindPhoneView.this).setEnabled(true);
                    q.a(UnbindPhoneView.g(UnbindPhoneView.this), com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.dA));
                    return;
                }
                e.a("UnbindPhoneView", new Object[] { "onReqDelAccountBind=", paramJSONObject });
                int i = paramJSONObject.optInt("errno", -1);
                if (i == 0) {
                    com.qihoo.gamecenter.sdk.common.a.c.e(null);
                    com.qihoo.gamecenter.sdk.common.a.c.a(true);
                    UnbindPhoneView.e(UnbindPhoneView.this).b();
                    q.a(UnbindPhoneView.g(UnbindPhoneView.this), com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.dB));
                }
                else if (i == 308) {
                    UnbindPhoneView.f(UnbindPhoneView.this);
                }
                else {
                    UnbindPhoneView.b(UnbindPhoneView.this).setEnabled(true);
                    UnbindPhoneView.c(UnbindPhoneView.this).setEnabled(true);
                    q.a(UnbindPhoneView.g(UnbindPhoneView.this), com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.dC));
                }
            }
        }, new String[] { com.qihoo.gamecenter.sdk.login.plugin.h.d.d(), com.qihoo.gamecenter.sdk.common.a.c.d() });
    }

    public void setOnUnbindListener(a parama) {
        this.k = parama;
    }

    private boolean a(Activity paramActivity, String paramString) {
        if (TextUtils.isEmpty(paramString)) {
            q.a(paramActivity, com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.f));
            return false;
        }
        if (paramString.length() < 2) {
            q.a(paramActivity, String.format(com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.S),
                    new Object[] { Integer.valueOf(2) }));
            return false;
        }
        if (TextUtils.isDigitsOnly(paramString)) {
            q.a(paramActivity, com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.U));
            return false;
        }
        if (paramString.toUpperCase(Locale.getDefault()).startsWith("360U")) {
            q.a(paramActivity, com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.V));
            return false;
        }
        if (paramString.length() > 14) {
            q.a(paramActivity, String.format(com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.T),
                    new Object[] { Integer.valueOf(14) }));
            return false;
        }
        if (com.qihoo.gamecenter.sdk.login.plugin.h.k.e(paramString)) {
            q.a(paramActivity, com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.X));
            return false;
        }
        if (!(com.qihoo.gamecenter.sdk.login.plugin.h.k.b(paramString))) {
            q.a(paramActivity, com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.W));
            return false;
        }
        return true;
    }

    public static abstract interface a {
        public abstract void a();

        public abstract void b();

        public abstract void c();

        public abstract void d();
    }
}